{extend name="./oscshop/admin/view/public/base.html" /}
{block name="content"}
<?php use think\Db; ?>
 
	<div class="page-header">
		<h1>
			{$breadcrumb2}
			<small>
				<i class="ace-icon fa fa-angle-double-right"></i>
				{$crumbs}
			</small>
		</h1>
	</div>	
	<ul class="nav nav-tabs">
		
	  <li class="active"><a href="#tab-order" data-toggle="tab">订单详情</a></li>
	 {if condition="$data['order']['shipping_method']"}
	  <li><a href="#tab-shipping" data-toggle="tab">收货地址</a></li>
	 {/if}
	  <li><a href="#tab-product" data-toggle="tab">商品清单</a></li>
	  
	  <li><a href="#tab-history" data-toggle="tab">订单历史</a></li>          
	  
	</ul>
	<div class="tab-content">
		<div class="tab-pane active" id="tab-order">
			<table class="table table-bordered">
				<tr>
				    <td>订单ID</td>
				    <td>{$data.order.order_id}</td>
				</tr>
				<tr>
					<td>订单编号</td>
					<td>{$data.order.order_num_alias}</td>
				</tr>
				<tr>
					<td>订单类型</td>
					<td>					
						{:get_goods_type_info(array('type'=>$data['order']['type']),'type')}	
					</td>
				</tr>
				 <tr>
		            <td>支付方式</td>
		            <td>		            	
						{:payment_name($data['order']['payment_code'])}	
		            </td>
		          </tr>
				<tr>
					<td>会员名称</td>
					<td>
							{$data.order.username}
					</td>
				</tr>
				<tr>
				    <td>电子邮件</td>
				    <td>{$data.order.email}</td>
				</tr>
				  <tr>
				    <td>联系电话</td>
				    <td>{$data.order.telephone}</td>
				</tr> 
				
				<tr>
				    <td>合计金额</td>
				    <td>					
						{:get_goods_type_info(array('type'=>$data['order']['type'],'price'=>$data['order']['total']),'price')}
				    </td>
				</tr>
				
				<tr>
				    <td>订单状态</td>
				    <td id="order-status"> 				    	
				    	{:get_order_status_name($data['order']['order_status_id'])}
				    </td>
				</tr>     
				<tr>
					<td>IP地址</td>
					<td>{$data.order.ip}</td>
				</tr>  
				<tr>
					<td>用户系统</td>
					<td>{$data.order.user_agent}</td>
				</tr>
				<tr>
					<td>下单时间</td>
					<td>{$data.order.date_added|date='Y/m/d H:i:s',###}</td>
				</tr>
				<tr>
					<td>修改时间</td>
					<td>
						{if condition="$data['order']['date_modified'] NEQ 0"}
							{$data.order.date_modified|date='Y/m/d H:i:s',###}
						{else/}
							无
						{/if}
					</td>
				</tr>
				</table>
		</div>
		{if condition="$data['order']['shipping_method']"}
		<div class="tab-pane" id="tab-shipping">
            <table class="table table-bordered">
          <tr>
            <td>收货人姓名</td>
            <td>{$data.order.shipping_name}</td>
          </tr>
                  
          <tr>
            <td>所在地</td>
            <td>
            	{:get_area_name($data['order']['shipping_province_id'])}
            	{:get_area_name($data['order']['shipping_city_id'])}
            	{:get_area_name($data['order']['shipping_country_id'])}            	
            </td>
          </tr>
          
          <tr>
            <td>地址</td>
            <td>{$data.order.address}</td>
          </tr>
         
         
           <tr>
          	<td>货运方式</td>
          	<td>
          		{:osc_system()->get_shipping($data['order']['shipping_method'],'title')}
          	</td>
          </tr>
          <tr>
          	<td>联系电话</td>
          	<td>{$data.order.shipping_tel}</td>
          </tr>
          
        </table>        
      </div>
      {/if}
      <div id="tab-product" class="tab-pane">
       <table class="table table-bordered">
          <thead>
            <tr>
              <td class="left">商品品名</td>
             
              <td class="right">型号</td>
              <?php if($data['order']['type']!=config('points_goods')){ ?>
              <td class="right">数量</td>         
              <td class="left">价格</td>     
              <td class="right">总计</td>
              <?php } ?>
            </tr>
          </thead>
          
          <?php if($data['order']['type']!=config('points_goods')){ ?>
          
          <tbody>
          	<?php if(isset($data['order_product'])&&is_array($data['order_product'])){ ?>
	            <?php foreach ($data['order_product'] as $product) { ?>
	            <tr>
	              <td class="left">
	              	<img src="IMG_ROOT{$product.image|resize=50,50}" />
	              	<a><?php echo $product['name']; ?></a>
	              	<?php if($option_list=Db::query('select * from '.config('database.prefix').'order_option where order_goods_id='.$product['order_goods_id'].' and order_id='.$product['order_id'])){ ?>
					<?php foreach ($option_list as $option) { ?>
	                <br />
	                &nbsp;<small> - <?php echo $option['name']; ?>: <?php echo $option['value']; ?></small>
	                <?php } ?>
	                <?php } ?>
	              </td>
	              <td class="left"><?php echo $product['model']; ?></td>
	              <td class="right">	              	
	              	<input name="quantity" type="text" size="2" class="quantity" order_id="<?php echo $data['order']['order_id']; ?>" order_goods_id="<?php echo $product['order_goods_id']; ?>" value="<?php echo $product['quantity']; ?>" />
	              </td>
	              
	              <td class="right">￥
	              	<input name="price" type="text" size="8" class="price" order_id="<?php echo $data['order']['order_id']; ?>" order_goods_id="<?php echo $product['order_goods_id']; ?>" value="<?php echo $product['price']; ?>" />
	              </td>
	              <td class="right">￥<?php echo $product['total']; ?></td>
	            </tr>
	            <?php } ?>
            <?php } ?>
    
          </tbody>
          <?php if(isset($data['order_total'])&&is_array($data['order_total'])){ ?>
	          <?php foreach ($data['order_total'] as $totals) { ?>
	          <tbody>
	            <tr>
	              <?php if($totals['code']=='shipping'){ ?>	
	              	<td colspan="4" class="right"><?php echo $totals['title']; ?>:</td>
	              	<td class="right">
	              		
	              		<?php if($data['order']['free_shipping']==1){ ?>	
	                	免运费
	                	<?php }else{ ?>
	                	￥<input id="shipping" order_id="<?php echo $data['order']['order_id']; ?>" type="text" size="8" value="<?php echo $totals['value']; ?>" />
	                	<?php } ?>
	                </td>
	              <?php }else{ ?>	
		              <td colspan="4" class="right"><?php echo $totals['title']; ?>:</td>
		              
		              <td class="right"><?php echo $totals['text']; ?></td>
	              <?php } ?>
	              
	              
	            </tr>
	          </tbody>
	          <?php } ?>
          <?php } ?>
          
          <?php }elseif($data['order']['type']==config('points_goods')){ ?>
          	<tbody>
          	<?php if(isset($data['order_product'])&&is_array($data['order_product'])){ ?>
	            <?php foreach ($data['order_product'] as $product) { ?>
	            <tr>
	              <td class="left">
	              	<a href="{:url('Goods/edit',array('id'=>$product['goods_id']))}"><?php echo $product['name']; ?></a>
	              	<?php if($option_list=Db::query('select * from '.config('database.prefix').'order_option where order_goods_id='.$product['order_goods_id'].' and order_id='.$product['order_id'])){ ?>
					<?php foreach ($option_list as $option) { ?>
	                <br />
	                &nbsp;<small> - <?php echo $option['name']; ?>: <?php echo $option['value']; ?></small>
	                <?php } ?>
	                <?php } ?>
	              </td>
	              
	              <td class="right">	              	
	              	<?php echo $product['quantity']; ?>
	              </td>
	              
	            </tr>
	            <?php } ?>
            <?php } ?>
    
          </tbody>
          
	          <tbody>
	            <tr>	             
		              <td colspan="2" class="right">积分: <?php echo $data['order']['total']; ?> </td>
		              
		                            
	            </tr>
	          </tbody>
	     
          <?php } ?>	
        </table>
  
      </div>
	
	
		 <div id="tab-history" class="tab-pane">
        <div id="history"></div>
        <table class="table table-bordered">
          <tr>
            <td>订单状态</td>
            <td>
              <input type="hidden" name="old_order_status_id" value="{$data.order.order_status_id}" id="old_order_status_id" />
              <select name="order_status_id">
                <?php foreach ($data['order_statuses'] as $order_statuses) { ?>
                	
                 <option value="<?php echo $order_statuses['order_status_id']; ?>" <?php if ($order_statuses['order_status_id'] == $data['order']['order_status_id']) { echo ' selected="selected"'; }?> ><?php echo $order_statuses['name']; ?></option>
               
                <?php } ?>
              </select>
            </td>
          </tr>
          <tr>
            <td>通知会员</td>
            <td><input type="checkbox" checked="checked" name="notify" value="1" /></td>
          </tr>
          <tr>
            <td>物流公司</td>
            <td>
            	
            	<select id="tcn" name="transport_c_name">
        		{volist name=":osc_system()->get_express()" id="e"}
	        		<option {if condition="!empty($data['order']['shipping_method']) and (osc_system()->get_shipping($data['order']['shipping_method'],'code') eq $key)"} selected="selected" {elseif condition="$data['order']['transport_c_name'] eq $key "/} selected="selected" {/if} value="{$key}">{$e}</option>
	        	{/volist}
	        </select> 
            </td>
          </tr>
          <tr>
            <td>物流单号</td>
            <td><input type="text" id="tn" name="transport_num" value="{$data.order.transport_num|default=''}" placeholder="物流单号，没有可不填" class="col-sm-3" /></td>
          </tr>
          
          <tr>
            <td>订单附言</td>
            <td><textarea name="comment" cols="40" rows="8" style="width: 99%"></textarea>
            </td>
           </tr>
           <tr>
           	<td colspan="2">
          <div class="text-right">
			<button id="button-history" class="btn btn-primary" data-loading-text="Loading...">
			<i class="fa fa-plus-circle"></i>
			添加订单记录
			</button>
		  </div>
		  </td>
          </tr>
        </table>
      </div>	
		
	</div>
{/block}
{block name="javascript"}
<script>	
//更新数量
$('.quantity').blur(function(){		
	$.post(
		"{:url('OrderBackend/update_order',array('type'=>'quantity'))}",
		{shipping:$('#shipping').val(),quantity:$(this).val(),order_id:$(this).attr('order_id'),order_goods_id:$(this).attr('order_goods_id')},
		function(data){
			if(data){
				window.location.reload();
			}
		}
	);
});
//更新价格
$('.price').blur(function(){		
	$.post(
		"{:url('OrderBackend/update_order',array('type'=>'price'))}",
		{shipping:$('#shipping').val(),price:$(this).val(),order_id:$(this).attr('order_id'),order_goods_id:$(this).attr('order_goods_id')},
		function(data){
			if(data){
				window.location.reload();
			}
		}
	);
});
//更新运费
$('#shipping').blur(function(){		
	$.post(
		"{:url('OrderBackend/update_shipping')}",
		{shipping:$('#shipping').val(),order_id:$(this).attr('order_id')},
		function(data){
			if(data){
				window.location.reload();
			}
		}
	);
});

$('#history').load('<?php echo url("OrderBackend/history",array("id"=>input("param.id"))); ?>');
$('#button-history').live('click', function() {

	$.ajax({
		url: '<?php echo url("OrderBackend/history",array("id"=>input("param.id"))); ?>',
		type: 'post',
		dataType: 'html',
		data: {
			order_status_id:$('select[name=\'order_status_id\']').val(),
			notify:$('input[name=\'notify\']').attr('checked') ? 1 : 0,
			comment:$('textarea[name=\'comment\']').val(),
			transport_c_name:$('#tcn').val(),
			transport_num:$('#tn').val()
		},
		
		beforeSend: function() {
			$('.success, .warning').remove();
			$('#button-history').attr('disabled', true);
			$('#history').prepend('<div class="attention"><img src="__PUBLIC__/image/loading.gif" alt="" />加载中...</div>');
		},
		complete: function() {
			$('#button-history').attr('disabled', false);
			$('.attention').remove();
		},
		success: function(html) {
			$('#history').html(html);
			
			$('textarea[name=\'comment\']').val('');
			
			$('#order-status').html($('select[name=\'order_status_id\'] option:selected').text());
		}
	});
});
</script>
{/block}